<template>
	<view class="list-wrapper">
		<view>
			<!-- <navigator url="company/info" open-type="navigate"> -->

			<view class="list-item" hover-class="list-item_active">
				<view class="div2-line"></view>
				<view class='item'>
					<image class='item2-image' src='../../static/img/my/student.png' mode='aspectFill' lazy-load='true' v-if="type == 2"></image>
					<image class='item2-image' src='../../static/img/my/teacher1.png' mode='aspectFill' lazy-load='true' v-if="type == 0"></image>
					<image class='item2-image' src='../../static/img/my/company.png' mode='aspectFill' lazy-load='true' v-if="type == 1"></image>
					<text class="item2-text">{{name}}</text>
					<!-- <button class="item2-text" hover-class='none' plain open-type="getUserInfo" @getuserinfo="bindGetUserInfo">登录</button> -->
				</view>
				<view class="div2-line"></view>
			</view>
			<!-- </navigator> -->
		</view>
		<view>
			<navigator url="company/info" open-type="navigate">
				<view class="list-item" hover-class="list-item_active">
					<view class='item'>
						<image class='item-image' src='../../static/img/my/info.png' mode='aspectFill' lazy-load='true'></image>
						<text class="item-text">我的信息</text>
						<view class='item-array'>
							<image src="../../static/img/my/info_68_68.jpg" class="img" mode="aspectFill" lazy-load="true"></image>
						</view>
					</view>
					<view class="div-line"></view>
				</view>
			</navigator>
		</view>
		<view>
			<navigator url="notice" open-type="navigate">
				<view class="list-item" hover-class="list-item_active">
					<view class='item'>
						<image class='item-image' src='../../static/img/my/msg.png' mode='aspectFill' lazy-load='true'></image>
						<text class="item-text">我的通知</text>
						<view class='item-array'>
							<image src="../../static/img/my/info_68_68.jpg" class="img" mode="aspectFill" lazy-load="true"></image>
						</view>
					</view>
					<view class="div-line"></view>
				</view>
			</navigator>
		</view>
		<view>
			<navigator url="help" open-type="navigate">
				<view class="list-item" hover-class="list-item_active">
					<view class='item'>
						<image class='item-image' src='../../static/img/my/help.png' mode='aspectFill' lazy-load='true'></image>
						<text class="item-text">帮助中心</text>
						<view class='item-array'>
							<image src="../../static/img/my/info_68_68.jpg" class="img" mode="aspectFill" lazy-load="true"></image>
						</view>
					</view>
					<view class="div-line"></view>
				</view>
			</navigator>
		</view>

		<view>
			<navigator url="/pages/my/about">
				<view class="list-item" hover-class="list-item_active">
					<view class='item'>
						<image class='item-image' src='../../static/img/my/about.png' mode='aspectFill' lazy-load='true'></image>
						<text class="item-text">关于我们</text>
						<view class='item-array'>
							<image src="../../static/img/my/info_68_68.jpg" class="img" mode="aspectFill" lazy-load="true"></image>
						</view>
					</view>
					<view class="div-line"></view>
				</view>
			</navigator>
		</view>


		<view v-if="role!=='student' && code !== 0">
			<view class="list-item" hover-class="list-item_active" @click="goDataAnalysls()">
				<view class='item'>
					<image class='item-image' src='../../static/img/my/lookdata.png' mode='aspectFill' lazy-load='true'></image>
					<text class="item-text">数据展示</text>
					<view class='item-array'>
						<image src="../../static/img/my/info_68_68.jpg" class="img" mode="aspectFill" lazy-load="true"></image>
					</view>
				</view>
				<view class="div-line"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		// getTest,
		getStudentInfo,
		getMsgsReceive
	} from '@/api/my/service.js';

	export default {
		data() {
			return {
				// Stuid: 0,
				studentInfo: null,
				navData: "",
				role: "s",
				name: "",
				type: 0,
				code: 1,
			}

		},
		created() {
			this.getMyData();
		},
		onLoad() {

			this.role = uni.getStorageSync("role");
			this.loadData();

		},
		methods: {
			bindGetUserInfo(e) {
				if (e.detail.userInfo) {
					//用户按了允许授权按钮
					console.log(e)
					// // 获取用户信息
					// uni.getUserInfo({
					// 	provider: 'weixin',
					// 	success: function(infoRes) {
					// 		console.log('-------获取微信用户所有-----');
					// 		console.log(JSON.stringify(infoRes.userInfo));
					// 	},
					// 	fail(res) {
					// 		console.log(res)
					// 	}
					// });
					console.log('App  1Show')
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {
							console.log(loginRes);

							// 获取用户信息
							uni.getUserInfo({
								provider: 'weixin',
								success: function(infoRes) {
									console.log('用户昵称为：' + infoRes.userInfo.nickName);

									console.log(JSON.stringify(infoRes.userInfo));
									uni.setStorage({ //缓存用户登陆状态
										key: 'userInfo',
										data: infoRes.userInfo
									})

								}
							});

							//获取用户openid 
							uni.request({
								url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wx16c25684cd81aa01&secret=db5ba94c62b6ba7b395c9a601e2e54f8&js_code=' +
									loginRes.code + '&grant_type=authorization_code',
								data: {
									text: 'uni.request'
								},
								header: {
									'custom-header': 'hello' //自定义请求头信息
								},
								success: (res) => {
									console.log(res);
									uni.setStorage({ //缓存用户openid 
										key: 'userInfoOpenId',
										data: res.data.openid
									})

								}
							});


						}
					});

				} else {
					//用户按了拒绝按钮
					console.log("用户按了拒绝按钮")
				}
			},
			topath() {
				uni.navigateTo({
					url: '../index/index',
					success: () => {
						console.log("123");
					}
				});
			},
			uploadImage() {
				uni.chooseImage({
					count: 1, //默认9
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
			},

			//页面跳转
			goDataAnalysls() {
				uni.navigateTo({
					url: './dataAnalysis/dataAnalysis'
				})
			},
			//获取数据
			getMyData() {
				const data = uni.getStorageSync("Infomation");
				if (this.role == 'teacher') {
					this.name = data.name;
				} else if (this.role == 'enterprise') {
					this.name = data.name;
				} else {
					this.name = data.name;
				}
			},
			loadData() {
				const token = uni.getStorageSync("token");
				if (this.role == 'teacher') {
					this.type = 0;
				} else if (this.role == 'enterprise') {
					this.type = 1;
				} else {
					this.type = 2;
				}
				console.log(token, this.type);
				getMsgsReceive(token, this.type).then(res => {
					if (res.data.code == 0) {
						this.name = "未登录";
						this.code = res.data.code;
					} else {
						this.notice = res.data;
						console.log(this.notice);
						uni.setStorage({
							key: "notice",
							data: res.data,
						});
					}
				}).catch(res => {
					console.log(res);
				});
			},
		}
	}
</script>

<style>
	body {
		color: #666;
	}

	.list-wrapper {
		width: 100%;
	}

	.div-line {
		background: #E0E3DA;
		width: 100%;
		height: 3rpx;
	}


	.list-item {
		width: 100%;
		height: 120rpx;
	}

	.list-item_active {
		background-color: #E0E3DA;
	}

	.item {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 120rpx;
	}

	.item-text {
		position: fixed;
		left: 100rpx;
		font-size: 35rpx;
	}

	.item-array {
		position: absolute;
		right: 50rpx;
	}

	.item-image {
		position: fixed;
		left: 50rpx;
		width: 40rpx;
		height: 40rpx;
	}

	.item2 {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 260rpx;
	}

	.item2-text {
		position: fixed;
		left: 120rpx;
		font-size: 34rpx;
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
		background: transparent;
		/*按钮背景透明*/
		border-width: 0px;
		/*边框透明*/
		outline: none;
		/*点击后没边框*/
	}


	button::after {
		border: none;
	}

	.item2-image {
		position: fixed;
		left: 50rpx;
		width: 47rpx;
		height: 47rpx;
	}

	.div2-line {
		background: #F5F5F5;
		width: 100%;
		height: 13rpx;
	}

	.img {
		width: 20rpx;
		height: 20rpx;
	}
</style>
